#include "VariableWrapper.h"
#include "FunctionContext.h"
#include <sstream>

VariableWrapper::VariableWrapper(SgInitializedName *set_name, SgDeclarationStatement *set_decl, FunctionContext *set_enclosing_function) { 
    aliases = NULL; 
    n_aliases = 0; 
    name = set_name; 
    decl = set_decl; 
    enclosing_function = set_enclosing_function; 
    SgType *rose_type = set_name->get_type();
    Argument *my_type = translateArgs(rose_type);
    type = my_type;
}

void VariableWrapper::addAlias(Reference *vw) {
    aliases = (Reference **)realloc(aliases, sizeof(Reference *) * (n_aliases+1));
    aliases[n_aliases] = vw;
    n_aliases++;
}

string VariableWrapper::str() {
    return name->get_name().str();
}

string VariableWrapper::func_str() {
    if(enclosing_function == NULL) {
        return "global";
    } else {
        return enclosing_function->get_name();
    }
}

string VariableWrapper::full_str() {
    stringstream ss;
    string type_str = type->typeStr();
    if(enclosing_function != NULL) {
        ss <<"[" <<enclosing_function->get_name()<<":"<<type_str<<" "<<name->get_name().str()<<"]";
    } else {
        ss << "[global:"<<type_str<<" "<<name->get_name().str()<<"]";
    }

    return ss.str();
}
